package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysRoleDTO;
import com.rabbit.eap.system.entity.SysRole;
import com.rabbit.eap.system.param.SysRolePageParam;
import com.rabbit.eap.system.service.ISysRoleService;
import com.rabbit.eap.system.vo.SysRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysRoleController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 角色信息表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysRole")
@Module("system")
@Api(value = "角色信息表API", tags = {"角色信息表"})
public class SysRoleController extends BaseController {

    @Autowired
    private ISysRoleService sysRoleService;


    /**
     * @param sysRoleDTO:sysRoleDTO数据传输对象
     * @Description: 添加角色信息表
     * @methodName: saveSysRole
     * @return: ApiResult.result(flag)
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PostMapping("/saveSysRole")
    @RequiresPermissions("sys:role:add")
    @OperationLog(name = "添加角色信息表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加角色信息表", response = ApiResult.class)
    public ApiResult saveSysRole(@Validated(AddGroup.class) @RequestBody SysRoleDTO sysRoleDTO) throws Exception {
        ApiResult apiResult = sysRoleService.saveSysRole(sysRoleDTO);
        return apiResult;
    }

    /**
     * @param sysRoleDTO:sysRoleDTO数据传输对象
     * @Description: 修改角色信息表
     * @methodName: modifySysRole
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysRole")
    @RequiresPermissions("sys:role:edit")
    @OperationLog(name = "修改角色信息表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改角色信息表", response = ApiResult.class)
    public ApiResult modifySysRole(@Validated(UpdateGroup.class) @RequestBody SysRoleDTO sysRoleDTO) throws Exception {
        ApiResult apiResult = sysRoleService.modifySysRole(sysRoleDTO);
        return apiResult;
    }

    /**
     * @param roleId:角色id
     * @Description: 删除角色信息表
     * @methodName: removeSysRole
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysRole")
    @RequiresPermissions("sys:role:remove")
    @OperationLog(name = "删除角色信息表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除角色信息表", response = ApiResult.class)
    public ApiResult removeSysRole(@RequestParam("roleId") Long roleId) throws Exception {
        ApiResult apiResult = sysRoleService.removeSysRole(roleId);
        return apiResult;
    }

    /**
     * @param id: id
     * @Description: 根据Id获取角色信息表详情
     * @methodName: getSysRoleInfo
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysRoleInfo")
    @RequiresPermissions("sys:role:query")
    @OperationLog(name = "角色信息表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "角色信息表详情", response = SysRoleVO.class)
    public ApiResult getSysRoleInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysRoleService.getSysRoleById(id);
        return apiResult;
    }

    /**
     * @param sysRolePageParam
     * @Description: 角色信息表分页列表
     * @methodName: getSysRolePageList
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("getSysRolePageList")
    @RequiresPermissions("sys:role:list")
    @OperationLog(name = "角色信息表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "角色信息表分页列表", response = SysRoleVO.class)
    public ApiResult getSysRolePageList(SysRolePageParam sysRolePageParam) throws Exception {
        ApiResult apiResult = sysRoleService.getSysRolePageList(sysRolePageParam);
        return apiResult;
    }

    /**
     * @param sysRoleDTO:
     * @Description: 修改角色状态
     * @methodName: modifySysRoleStatus
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/9 22:12
     * @author: rabbit
     */
    @PutMapping("/modifySysRoleStatus")
    @RequiresPermissions("sys:role:edit")
    @OperationLog(name = "修改角色状态", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改角色状态", response = ApiResult.class)
    public ApiResult modifySysRoleStatus(@RequestBody SysRoleDTO sysRoleDTO) throws Exception {
        ApiResult apiResult = sysRoleService.modifySysRoleStatus(sysRoleDTO);
        return apiResult;
    }

    /**
     * @param :
     * @Description: 获取角色选择框列表
     * @methodName: getSysRoleSelect
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/9 22:29
     * @author: rabbit
     */
    @GetMapping("/getSysRoleSelect")
    @RequiresPermissions("sys:role:query")
    @OperationLog(name = "获取角色选择框列表", type = OperationLogType.LIST)
    @ApiOperation(value = "获取角色选择框列表", response = ApiResult.class)
    public ApiResult getSysRoleSelect() throws Exception {
        ApiResult apiResult = sysRoleService.getSysRoleSelect();
        return apiResult;
    }

    /**
     * @param sysRole:
     * @Description: 分配数据权限
     * @methodName: authDataScope
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/9 23:07
     * @author: rabbit
     */
    @PutMapping("/authDataScope")
    @RequiresPermissions("sys:role:edit")
    @OperationLog(name = "数据权限", type = OperationLogType.UPDATE)
    @ApiOperation(value = "数据权限", response = ApiResult.class)
    public ApiResult authDataScope(@RequestBody SysRole sysRole) throws Exception {
        ApiResult apiResult = sysRoleService.authDataScope(sysRole);
        return apiResult;
    }

    /**
     * @param sysRole:
     * @Description: 分配菜单权限
     * @methodName: authRoleMenu
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/12 21:53
     * @author: rabbit
     */
    @PutMapping("/authRoleMenu")
    @RequiresPermissions("sys:role:edit")
    @OperationLog(name = "分配菜单权限", type = OperationLogType.UPDATE)
    @ApiOperation(value = "分配菜单权限", response = ApiResult.class)
    public ApiResult authRoleMenu(@RequestBody SysRole sysRole) throws Exception {
        ApiResult apiResult = sysRoleService.authRoleMenu(sysRole);
        return apiResult;
    }

    /**
     * @param :
     * @Description: 获取所有角色
     * @methodName: getRoleList
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/9/25 20:00
     * @author: rabbit
     */
    @GetMapping("/getRoleList")
    @OperationLog(name = "获取所有角色", type = OperationLogType.LIST)
    @ApiOperation(value = "获取所有角色", response = ApiResult.class)
    public ApiResult getRoleList() {
        ApiResult apiResult = sysRoleService.getRoleList();
        return apiResult;
    }
}

